/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GameObject;

import FrameWork.Models.GLModel;
import java.util.ArrayList;
import utils.POINT;
import utils.Vector3;

/**
 *
 * @author QuyNguyenNam
 */
public class CannonPiece extends ChessPiece {

    public CannonPiece(GLModel md, Vector3 pos) {
        super(md, pos);
    }

    public CannonPiece(GLModel md, POINT point) {
        super(md, point);
    }

    public CannonPiece(int nameID, POINT point) {
        super(nameID, point);
    }
    
    @Override
    public ArrayList<POINT> getListCanGo(int[][] map) {
        ArrayList<POINT> result = new ArrayList<POINT>();
        POINT tmpPOINT = null;

        // check trai
        if (canMoveLeft(map)) {
            int y = point.y - 1;
            while (y >= 1) {
                tmpPOINT = new POINT(point.x, y);    
                if (isEmptyLocation(map, tmpPOINT) == false) {
                    y--;
                    while (y >= 1) {
                        tmpPOINT = new POINT(point.x, y);  
                        if (isEmptyLocation(map, tmpPOINT) == false)
                        {
                            if (!(tmpPOINT.x < 1 || tmpPOINT.x > 10 || tmpPOINT.y < 1 || tmpPOINT.y > 9)) {
                                if (isOpponent(nameID, map[tmpPOINT.x][tmpPOINT.y])) {
                                    result.add(tmpPOINT);
                                    break;
                                }
                            }
                        }
                        y--;
                    }
                    break;
                }

                result.add(tmpPOINT);   
                y--;
            }
        }

        // check tren
        if (canMoveUp(map)) {
            int x = point.x - 1;
            while (x >= 1) {
                tmpPOINT = new POINT(x, point.y);    
                if (isEmptyLocation(map, tmpPOINT) == false) {
                    x--;
                    while (x >= 1) {
                        tmpPOINT = new POINT(x, point.y);  
                        if (isEmptyLocation(map, tmpPOINT) == false)
                        {
                            if (!(tmpPOINT.x < 1 || tmpPOINT.x > 10 || tmpPOINT.y < 1 || tmpPOINT.y > 9)) {
                                if (isOpponent(nameID, map[tmpPOINT.x][tmpPOINT.y])) {
                                    result.add(tmpPOINT);
                                    break;
                                }
                            }
                        }
                        x--;
                    }
                    break;
                }

                result.add(tmpPOINT);   
                x--;
            }
        }

        // check phai
        if (canMoveRight(map)) {
            int y = point.y + 1;
            while (y <= 9) {
                tmpPOINT = new POINT(point.x, y);    
                if (isEmptyLocation(map, tmpPOINT) == false) {
                    y++;
                    while (y <= 9) {
                        tmpPOINT = new POINT(point.x, y);  
                        if (isEmptyLocation(map, tmpPOINT) == false)
                        {
                            if (!(tmpPOINT.x < 1 || tmpPOINT.x > 10 || tmpPOINT.y < 1 || tmpPOINT.y > 9)) {
                                if (isOpponent(nameID, map[tmpPOINT.x][tmpPOINT.y])) {
                                    result.add(tmpPOINT);
                                    break;
                                }
                            }
                        }
                        y++;
                    }
                    break;
                }

                result.add(tmpPOINT);   
                y++;
            }
        }

        // check duoi
        if (canMoveDown(map)) {
            int x = point.x + 1;
            while (x <= 10) {
                tmpPOINT = new POINT(x, point.y);    
                if (isEmptyLocation(map, tmpPOINT) == false) {
                    x++;
                    while (x <= 10) {
                        tmpPOINT = new POINT(x, point.y);  
                        if (isEmptyLocation(map, tmpPOINT) == false)
                        {
                            if (!(tmpPOINT.x < 1 || tmpPOINT.x > 10 || tmpPOINT.y < 1 || tmpPOINT.y > 9)) {
                                if (isOpponent(nameID, map[tmpPOINT.x][tmpPOINT.y])) {
                                    result.add(tmpPOINT);
                                    break;
                                }
                            }
                        }
                        x++;
                    }
                    break;
                }

                result.add(tmpPOINT);   
                x++;
            }
        }

        return result;
    }

    @Override
    public boolean canMoveLeft(int[][] map) {
        if (point.y == 1) {
            return false;
        }

        return true;
    }

    @Override
    public boolean canMoveUp(int[][] map) {
        if (point.x == 1) {
            return false;
        }

        return true;
    }

    @Override
    public boolean canMoveRight(int[][] map) {
        if (point.y == 9) {
            return false;
        }

        return true;
    }

    @Override
    public boolean canMoveDown(int[][] map) {
        if (point.x == 10) {
            return false;
        }

        return true;
    }
}
